import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'relatedPositionM',
  state: {
    columns: [
      {
        title: '证券代码',
        dataIndex: 'securitiesCode',
        key: 'securitiesCode',
      },
      {
        title: '证券全称',
        dataIndex: 'securitiesName',
        key: 'securitiesName',
      },
      {
        title: '产品代码',
        dataIndex: 'productCode',
        key: 'productCode',
      },
      {
        title: '产品简称',
        dataIndex: 'productName',
        key: 'productName',
      },
      {
        title: '持仓数量',
        dataIndex: 'amount',
        key: 'amount',
        type: 'number',
      },
      {
        title: '持仓状态',
        dataIndex: 'status',
        key: 'status',
        type: 'filterCol',
        width: 100,
        filters: [
          {
            text: '存续',
            value: '1',
          },
          {
            text: '历史',
            value: '0',
          },
        ],
        onFilter: (value, record) => {
          if (value == 0) {
            return record.amount == 0;
          }
          return record.amount > 0;
        },
        render: (v, record) => {
          if (record.amount) {
            return '存续';
          } else {
            return '历史';
          }
        },
      },
    ],
    currentColumns: [
      {
        title: '交易日期',
        dataIndex: 'tradeDt',
        key: 'tradeDt',
        type: 'date',
      },
      {
        title: '交易方向',
        dataIndex: 'jyfx',
        key: 'jyfx',
      },
      {
        title: '成交数量',
        dataIndex: 'dealAmount',
        key: 'dealAmount',
        type: 'number',
      },
      {
        title: '成交价格',
        dataIndex: 'dealValue',
        key: 'dealValue',
        type: 'money',
        toFixed: '4',
      },
      {
        title: '成交全价',
        dataIndex: 'dealFullPrice',
        key: 'dealFullPrice',
        type: 'money',
        toFixed: '4',
      },
      {
        title: '成交金额',
        dataIndex: 'totalDeallValue',
        key: 'totalDeallValue',
        type: 'money',
      },
      {
        title: '费用',
        dataIndex: 'fee',
        key: 'fee',
        type: 'money',
      },
    ],
  },
  effects: {
    // 获取关联持仓列表
    *getTableDate({ payload, callback }, { call, put }) {
      const response = yield call(api.nonStandard.getRelatedPosition, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg || '获取关联持仓列表失败！');
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
